package com.wwwarehouse.taskcenter.fragment.warehouse_reg;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.bean.upload.FileUploadBean;
import com.wwwarehouse.common.common.Common;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.ClearEditText;
import com.wwwarehouse.common.custom_widget.keyboard.VirtualKeyboardView;
import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.custom_widget.time_pick.ChoosePickerDialog;
import com.wwwarehouse.common.http.NetUtils;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.ThreadUtils;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.BillBean;
import com.wwwarehouse.taskcenter.bean.ChooseCarriageBean;
import com.wwwarehouse.taskcenter.bean.KeyBoardItemBean;
import com.wwwarehouse.taskcenter.bean.MediaBean;
import com.wwwarehouse.taskcenter.bean.StorageRegistBean;
import com.wwwarehouse.taskcenter.bean.UnitBean;
import com.wwwarehouse.taskcenter.constant.TaskCenterConstant;
import com.wwwarehouse.taskcenter.custom_view.CarNumDialog;
import com.wwwarehouse.taskcenter.eventbus_event.CarriageEvent;
import com.wwwarehouse.taskcenter.eventbus_event.OwnerEvent;
import com.wwwarehouse.taskcenter.interfaces.XmlParse;
import com.wwwarehouse.taskcenter.interfaces.impl.DomParse;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

/**
 * Created by clannad.shao on 2017/11/16.
 *
 * @author clannad_sk
 * @date 2017/11/16
 * 入库登记fragment
 */
public class WhouseRegSecFragment extends BaseFragment implements View.OnClickListener,
        ClearEditText.onMyFocusChangeListener, EasyPopupWindow.ChildClickListener {

    private RelativeLayout idWareSecOwnerRl;
    private ImageView idWareSecNameIv;
    private TextView idWareSecNameTv;
    private RelativeLayout idWareSecCarryRl;
    private ImageView idWareSecCarryIv;
    private TextView idWareSecCarryTv;
    private TextView idWareSecGoodsTsTv;
    private TextView idWareSecGoodsNumTv;
    private TextView idWareSecGoodsTv;
    private ImageView idWareSecGoodsIv;
    private TextView idWareSecCarTsTv;
    private ClearEditText idWareSecCarEt;
    private RelativeLayout idWareSecCarRl;
    private TextView idWareSecCarTv;
    private TextView idWareSecDriverTsTv;
    private ClearEditText idWareSecDriverEt;
    private TextView idWareSecDriPhoneTsTv;
    private ClearEditText idWareSecDriPhoneEt;
    private TextView idWareSecPreStepTv;
    private TextView idWareSecCompleteTv;
    private RelativeLayout idWareSecGoodsRl;
    private List<UnitBean> unitBeanList;
    private List<String> goodsUnitList;
    private View keyBoardView;
    private List<KeyBoardItemBean> keyBoardItems;
    private int selection = 2;
    private EasyPopupWindow mEasyPopupWindow;
    private static final String REQUEST_SUCCESS_CODE = "0";
    private static final int REQUEST_GOODS_UNIT_CODE = 20;
    private static final int REQUEST_GOODS_UNIT_TWICE_CODE = 21;
    private static final int REQUEST_CHECK_NUM_CODE = 22;
    private static final int REQUEST_SAVE_WHOUSE_REGIST = 23;
    private boolean isReady;
    private boolean isComplete;
    /**
     * 监视进程 定义全局变量便于管理生命周期
     */
    private Runnable watcherRunnable;
    private Map<Object, Object> paramMap;
    private Map<String, Object> requestMap;
    private static final String POSITION_OWNER = "ownerUkid";
    private static final String POSITION_CARRIAGE = "expressBrandUkid";
    private static final String POSITION_GOODS_NUM = "qty";
    private static final String POSITION_UNIT = "unit";
    private static final String POSITION_CAR_NUM_FIRST = "carNoFirst";
    private static final String POSITION_CAR_NUM_Sec = "carNoSec";
    private static final String POSITION_DRIVER_NAME = "driverName";
    private static final String POSITION_DRIVER_PHONE = "driverPhone";
    private StorageRegistBean storageRegistBean;
    private List<MediaBean> mediaList;
    private String carNum;
    private String jobPointUkid;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.task_center_warehouse_reg_secstep, container, false);
    }

    /**
     * initView
     *
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        isReady = false;
        isComplete = false;
        paramMap = new HashMap<>();
        requestMap = new HashMap<>();
        storageRegistBean = new StorageRegistBean();
        mediaList = new ArrayList<>();
        Bundle bundle = getArguments();
        if (bundle != null) {
            BillBean billBean = (BillBean) bundle.get(getString(R.string.whouse_reg_billUnit));
            jobPointUkid = bundle.getString("jobPointUkid");
            storageRegistBean.setBillType(billBean != null ? billBean.getCode() : "");
            storageRegistBean.setBusinessNo((String) bundle.get(getString(R.string.whouse_reg_billNum)));
            storageRegistBean.setRegistTime((String) bundle.get(getString(R.string.whouse_reg_dateTime)));
            FileUploadBean.DataBean dataBean = (FileUploadBean.DataBean) bundle.getSerializable(getString(R.string.whouse_reg_img1));
            MediaBean mediaBean = new MediaBean();
            mediaBean.setMediaName(getString(R.string.whouse_reg_billimg));
            mediaBean.setRelatedUrl(dataBean.getFullPath());
            mediaList.add(mediaBean);

            dataBean = (FileUploadBean.DataBean) bundle.getSerializable(getString(R.string.whouse_reg_img2));
            mediaBean = new MediaBean();
            mediaBean.setMediaName(getString(R.string.whouse_reg_carimg));
            mediaBean.setRelatedUrl(dataBean.getFullPath());
            mediaList.add(mediaBean);

            dataBean = (FileUploadBean.DataBean) bundle.getSerializable(getString(R.string.whouse_reg_img3));
            mediaBean = new MediaBean();
            mediaBean.setMediaName(getString(R.string.whouse_reg_cargoodsimg));
            mediaBean.setRelatedUrl(dataBean.getFullPath());
            mediaList.add(mediaBean);
            System.out.println(mediaList);
        }
        //初始化view
        idWareSecOwnerRl = $(R.id.idWareSecOwnerRl);
        idWareSecNameIv = $(R.id.idWareSecNameIv);
        idWareSecNameTv = $(R.id.idWareSecNameTv);
        idWareSecCarryRl = $(R.id.idWareSecCarryRl);
        idWareSecCarryIv = $(R.id.idWareSecCarryIv);
        idWareSecCarryTv = $(R.id.idWareSecCarryTv);
        idWareSecGoodsTsTv = $(R.id.idWareSecGoodsTsTv);
        idWareSecGoodsTv = $(R.id.idWareSecGoodsTv);
        idWareSecGoodsNumTv = $(R.id.idWareSecGoodsNumTv);
        idWareSecGoodsIv = $(R.id.idWareSecGoodsIv);
        idWareSecCarTsTv = $(R.id.idWareSecCarTsTv);
        idWareSecCarEt = $(R.id.idWareSecCarEt);
        idWareSecCarRl = $(R.id.idWareSecCarRl);
        idWareSecCarTv = $(R.id.idWareSecCarTv);
        idWareSecDriverTsTv = $(R.id.idWareSecDriverTsTv);
        idWareSecDriverEt = $(R.id.idWareSecDriverEt);
        idWareSecDriPhoneTsTv = $(R.id.idWareSecDriPhoneTsTv);
        idWareSecDriPhoneEt = $(R.id.idWareSecDriPhoneEt);
        idWareSecPreStepTv = $(R.id.idWareSecPreStepTv);
        idWareSecCompleteTv = $(R.id.idWareSecCompleteTv);
        idWareSecGoodsRl = $(R.id.idWareSecGoodsRl);
        idWareSecOwnerRl.setOnClickListener(this);
        idWareSecCarryRl.setOnClickListener(this);
        idWareSecGoodsRl.setOnClickListener(this);
        idWareSecCarRl.setOnClickListener(this);
        idWareSecGoodsNumTv.setOnClickListener(this);
        idWareSecCompleteTv.setOnClickListener(this);
        idWareSecCompleteTv.setClickable(false);

        addTextWatcher();

        idWareSecCarEt.setOnMyFocusChangeListener(this);
        idWareSecDriverEt.setOnMyFocusChangeListener(this);
        idWareSecDriPhoneEt.setOnMyFocusChangeListener(this);
        goodsUnitList = new ArrayList<>();

        //默认车牌号首位
        paramMap.put(POSITION_CAR_NUM_FIRST, getString(R.string.warehouse_reg_carnum_firstdefault));
        requestData(REQUEST_GOODS_UNIT_CODE, TaskCenterConstant.GET_GOODS_UNIT, new HashMap<String, Object>());
        watcherRunnable = new WatcherRunnable();
        ThreadUtils.newThread(watcherRunnable);
    }

    private void addTextWatcher() {
        idWareSecCarEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                paramMap.put(POSITION_CAR_NUM_Sec, s.toString());
                if (StringUtils.isNullString(s.toString())) {
                    isComplete = false;
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        idWareSecDriverEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                paramMap.put(POSITION_DRIVER_NAME, s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        idWareSecDriPhoneEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                paramMap.put(POSITION_DRIVER_PHONE, s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    /**
     * REQUEST
     *
     * @param what
     * @param url
     * @param map
     */
    private void requestData(int what, String url, Map<String, Object> map) {
        if (!NetUtils.isHttpConnected(mActivity)) {
            toast(getString(R.string.warehouse_reg_no_network));
        }
        NoHttpUtils.httpPost(url, map, new NoHttpUtils.OnResponseListener() {
            @Override
            public void onSucceed(CommonClass commonClass, int what) {
                if (REQUEST_GOODS_UNIT_CODE == what) {
                    //进入页面获取单位请求
                    if (!REQUEST_SUCCESS_CODE.equals(commonClass.getCode())) {
                        //第一次获取单位badRequest静默处理
                        return;
                    }
                    //成功
                    unitBeanList = JSONObject.parseArray(commonClass.getData().toString(), UnitBean.class);
                    if (unitBeanList == null || unitBeanList.isEmpty()) {
                        return;
                    }
                    for (UnitBean unitBean : unitBeanList) {
                        goodsUnitList.add(StringUtils.isNullString(unitBean.getUnitName()) ? "" : unitBean.getUnitName());
                    }
                } else if (REQUEST_GOODS_UNIT_TWICE_CODE == what) {
                    //第二次获取单位
                    if (!REQUEST_SUCCESS_CODE.equals(commonClass.getCode())) {
                        //badRequest
                        toast(getString(R.string.warehouse_reg_getgoodsunit_error));
                        return;
                    }
                    unitBeanList = JSONObject.parseArray(commonClass.getData().toString(), UnitBean.class);
                    if (unitBeanList == null || unitBeanList.isEmpty()) {
                        toast(getString(R.string.warehouse_reg_getgoodsunit_error));
                        return;
                    }
                    for (UnitBean unitBean : unitBeanList) {
                        goodsUnitList.add(StringUtils.isNullString(unitBean.getUnitName()) ? "" : unitBean.getUnitName());
                    }
                    showGoodsUnitDialog();
                } else if (REQUEST_CHECK_NUM_CODE == what) {
                    //车牌校验
                    if (!REQUEST_SUCCESS_CODE.equals(commonClass.getCode())) {
                        toast(getString(R.string.whouse_reg_checkcarnum_failed));
                        return;
                    }
                    //成功。发起保存请求
                    saveDataRequest();
                } else if (REQUEST_SAVE_WHOUSE_REGIST == what) {
                    //保存入库信息请求
                    if (!REQUEST_SUCCESS_CODE.equals(commonClass.getCode())) {
                        toast(getString(R.string.whouse_reg_save_error));
                        return;
                    }
                    //保存成功  跳转下个页面
                    String goodsNum = (String) paramMap.get(POSITION_GOODS_NUM);
                    String driverName = (String) paramMap.get(POSITION_DRIVER_NAME);
                    String driverPhone = (String) paramMap.get(POSITION_DRIVER_PHONE);
                    ChooseCarriageBean.Carriage carriage = (ChooseCarriageBean.Carriage) paramMap.get("carriage");
                    Fragment fragment = new WhouseRegSuccessFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("owner", "xxx");
                    bundle.putString("dateTime", storageRegistBean.getRegistTime());
                    bundle.putString("billType", storageRegistBean.getBillType());
                    bundle.putString("billNum", storageRegistBean.getBusinessNo());
                    bundle.putString("carriage", carriage.getBrandName());
                    bundle.putString("carNo", storageRegistBean.getCarNo());
                    bundle.putString("driverName", driverName);
                    bundle.putString("driverPhone", driverPhone);
                    fragment.setArguments(bundle);
                    pushFragment(fragment);
                } else {
                    //otherRequest
                }
            }

            @Override
            public void onFailed(String result, int what) {
                if(StringUtils.isNullString(result)){
                    return;
                }
                toast(result);
            }

            @Override
            public void onFinish(int what) {

            }
        }, what);

    }


    /**
     * onclick
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        if (Common.getInstance().isNotFastClick()) {
            if (view.getId() == R.id.idWareSecOwnerRl) {
                //货主点击选择
                pushFragment(new ChooseOwnerFragment());
            } else if (view.getId() == R.id.idWareSecCarryRl) {
                //承运商点击选择
                pushFragment(new ChooseCarriageFragment());
            } else if (view.getId() == R.id.idWareSecGoodsNumTv) {
                //商品数量点击输入
                hideInput(view);
                showGoodsNumPop();
            } else if (view.getId() == R.id.idWareSecGoodsRl) {
                //商品单位点击选择
                hideInput(view);
                showGoodsUnitDialog();
            } else if (view.getId() == R.id.idWareSecCarRl) {
                //车牌号第一位点击选择
                showCarNumDialog(view);
            } else if (view.getId() == R.id.idWareSecCompleteTv) {
                //完成按钮
                checkAndRequest();
            } else {
                //default占位

            }
        } else {
            toast(getString(R.string.warehouse_reg_cliclfast));
        }

    }

    //TODO 差货主 司机号码
    private void checkAndRequest() {
        //先校验车牌号
        Map<String, Object> checkCarNumMap = new HashMap<>();
        String carNumFirst = (String) paramMap.get(POSITION_CAR_NUM_FIRST);
        String carNumSec = (String) paramMap.get(POSITION_CAR_NUM_Sec);
        carNum = carNumFirst + (StringUtils.isNullString(carNumSec) ? "" : carNumSec.toUpperCase());
        checkCarNumMap.put("carNumber", carNum);
        requestData(REQUEST_CHECK_NUM_CODE, TaskCenterConstant.CHECK_CAR_NUM, checkCarNumMap);
    }

    private void saveDataRequest() {
        String goodsNum = (String) paramMap.get(POSITION_GOODS_NUM);
        String driverName = (String) paramMap.get(POSITION_DRIVER_NAME);
        String driverPhone = (String) paramMap.get(POSITION_DRIVER_PHONE);
        UnitBean unitBean = (UnitBean) paramMap.get(POSITION_UNIT);
        ChooseCarriageBean.Carriage carriage = (ChooseCarriageBean.Carriage) paramMap.get("carriage");

        storageRegistBean.setQty(StringUtils.isNullString(goodsNum) ? 0 : Long.parseLong(goodsNum));
        storageRegistBean.setContactName(StringUtils.isNullString(driverName) ? "" : driverName);
        storageRegistBean.setContactPhone(StringUtils.isNullString(driverPhone) ? "" : driverPhone);
        storageRegistBean.setExpressBrandUkid(carriage == null ? 0 : (StringUtils.isNullString(carriage.getBrandUkid())
                ? 0 : Long.parseLong(carriage.getBrandUkid())));
        storageRegistBean.setUnitName(unitBean == null ? "" : (StringUtils.isNullString(unitBean.getUnitName())
                ? "" : unitBean.getUnitName()));
        storageRegistBean.setUnitUkid(unitBean == null ? 0 : unitBean.getUnitUkid());
        storageRegistBean.setCarNo(StringUtils.isNullString(carNum) ? "" : carNum);
        requestMap.put("swStorageRegist", storageRegistBean);
        requestMap.put("userId", sp.getValue(Constant.sp_User_Id));
        requestMap.put("mediaList", mediaList);
        requestMap.put("jobPointUkid", jobPointUkid);

        requestData(REQUEST_SAVE_WHOUSE_REGIST, TaskCenterConstant.SAVE_STORAGE_REGIST, requestMap);
    }

    /**
     * 商品数量键盘pop
     */
    private void showGoodsNumPop() {
        idWareSecGoodsTsTv.setVisibility(View.VISIBLE);
        View popView = View.inflate(mActivity, R.layout.popupwindow_inputboard_layout, null);
        VirtualKeyboardView virtualKeyboardView = (VirtualKeyboardView) popView.findViewById(R.id.number);
        virtualKeyboardView.isShowContentBar(true);
        virtualKeyboardView.setOnInputDataConfirmListener(new VirtualKeyboardView.OnInputDataConfirmListener() {
            @Override
            public void InputDataConfirm(String text) {
                if (StringUtils.isNullString(text)) {
                    toast(getString(R.string.warehouse_reg_error_goodsnum));
                    return;
                }
                mEasyPopupWindow.dismiss();
                idWareSecGoodsTsTv.setVisibility(View.VISIBLE);
                idWareSecGoodsNumTv.setTextColor(Color.parseColor("#000000"));
                idWareSecGoodsNumTv.setText(StringUtils.isNullString(text) ? "" : text);
                paramMap.put(POSITION_GOODS_NUM, text);
            }
        });
        mEasyPopupWindow = new EasyPopupWindow.Builder(mActivity)
                //设置popupwindow view 里面可以传view, layout
                .setView(popView)
                //设置宽高
                .setSize(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                //设置背景透明度
                .setBackgroundAlpha(0.7f)
                //设置动画
                .setAnim(R.style.anim_menu_bottom_bar)
                //设置动画
                .setAnim(com.wwwarehouse.common.R.style.anim_menu_bottom_bar)
                //点击外面是否关闭
                .setOutsideTouchHide(true)
                //布局中的事件回调
                .setOnChildClickListener(this)
                .create(); //创建
        mEasyPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (getString(R.string.warehouse_reg_entergoodsnum).equals(idWareSecGoodsNumTv.getText().toString().trim())) {
                    idWareSecGoodsTsTv.setVisibility(View.INVISIBLE);
                } else {
                    idWareSecGoodsTsTv.setVisibility(View.VISIBLE);
                }
            }
        });

        mEasyPopupWindow.showAtLocation(mActivity.findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
    }

    /**
     * 商品单位选择
     */
    private void showGoodsUnitDialog() {
        if (goodsUnitList == null || goodsUnitList.isEmpty()) {
            //没有数据
            requestData(REQUEST_GOODS_UNIT_TWICE_CODE, TaskCenterConstant.GET_GOODS_UNIT, new HashMap<String, Object>());
            return;
        }
        new ChoosePickerDialog.Builder(mActivity)
                .setData(goodsUnitList)
                .setTitle(getString(R.string.warehouse_reg_pick_bill))
                .setOnDataSelectedListener(new ChoosePickerDialog.OnSelectedListener() {
                    @Override
                    public void onSelected(String s, int i) {
                        idWareSecGoodsTv.setText(s);
                        paramMap.put(POSITION_UNIT, unitBeanList.get(i));
                    }

                    @Override
                    public void onCancel() {

                    }
                })
                .create()
                .show();
    }

    /**
     * 车牌号码第一位
     *
     * @param view
     */
    private void showCarNumDialog(View view) {
        InputMethodManager imm = (InputMethodManager)
                mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        try {
            keyBoardView = LayoutInflater.from(mActivity).inflate(R.layout.task_center_carnum_keyboard, null);
            XmlParse xmlParse = new DomParse();
            InputStream is = mActivity.getAssets().open("province.xml");
            keyBoardItems = xmlParse.parse(is);

            new CarNumDialog.Builder(mActivity)
                    .setContentView(keyBoardView)
                    .setData(keyBoardItems)
                    .setSelection(selection)
                    .setOnDataSelectedListener(new CarNumDialog.OnSelectedListener() {
                        @Override
                        public void onSelected(String s, int pos) {
                            toast(s);
                            idWareSecCarTv.setText(StringUtils.isNullString(s) ? getString(R.string.warehouse_reg_default_carnum) : s);
                            selection = pos;
                            paramMap.put(POSITION_CAR_NUM_FIRST, s);
                        }

                        @Override
                        public void onCancel() {

                        }
                    })
                    .create()
                    .show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 监听线程
     */
    class WatcherRunnable implements Runnable {

        @Override
        public void run() {
            while (!isReady) {
                if (paramMap.containsKey(POSITION_CAR_NUM_FIRST) && !StringUtils.isNullString((String) paramMap.get(POSITION_CAR_NUM_FIRST)) &&
                        paramMap.containsKey(POSITION_CAR_NUM_Sec) && !StringUtils.isNullString((String) paramMap.get(POSITION_CAR_NUM_Sec)) &&
                        paramMap.containsKey(POSITION_GOODS_NUM) && !StringUtils.isNullString((String) paramMap.get(POSITION_GOODS_NUM)) &&
                        paramMap.containsKey(POSITION_UNIT) && paramMap.get(POSITION_UNIT) != null &&
                        !isComplete) {
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            idWareSecCompleteTv.setClickable(true);
                            idWareSecCompleteTv.setBackground(getResources().getDrawable(R.drawable.task_center_nextbt_background_blue));
                            isComplete = true;
                        }
                    });
                }
            }
        }
    }

    /**
     * 焦点事件
     *
     * @param view
     * @param hasFocus
     */
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (view.getId() == R.id.idWareSecCarEt) {
            //请输入车牌号码
            idWareSecCarTsTv.setVisibility(hasFocus ? View.VISIBLE :
                    (StringUtils.isNullString(idWareSecCarEt.getText().toString().trim()) ? View.INVISIBLE : View.VISIBLE));
        } else if (view.getId() == R.id.idWareSecDriverEt) {
            //司机姓名
            idWareSecDriverTsTv.setVisibility(hasFocus ? View.VISIBLE :
                    (StringUtils.isNullString(idWareSecDriverEt.getText().toString().trim()) ? View.INVISIBLE : View.VISIBLE));
        } else if (view.getId() == R.id.idWareSecDriPhoneEt) {
            //司机手机号
            idWareSecDriPhoneTsTv.setVisibility(hasFocus ? View.VISIBLE :
                    (StringUtils.isNullString(idWareSecDriPhoneEt.getText().toString().trim()) ? View.INVISIBLE : View.VISIBLE));
        } else {
            //default占位
        }
    }

    public void onEventMainThread(Object event) {
        if(event instanceof CarriageEvent){
            CarriageEvent dataEvent = (CarriageEvent) event;
            if (dataEvent == null || dataEvent.getCarriage() == null) {
                return;
            }
            idWareSecCarryTv.setText(StringUtils.isNullString(dataEvent.getCarriage().getBrandName()) ?
                    "" : dataEvent.getCarriage().getBrandName());
            paramMap.put("carriage", dataEvent.getCarriage());
        }else if(event instanceof OwnerEvent){
            OwnerEvent dataEvent = (OwnerEvent) event;
            if(dataEvent == null || dataEvent.getOwnerBean() == null){
                return;
            }
            idWareSecNameTv.setText(StringUtils.isNullString(dataEvent.getOwnerBean().getBusinessUnitName()) ?
                    "" : dataEvent.getOwnerBean().getBusinessUnitName());
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        isReady = true;
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        if (watcherRunnable != null) {
            watcherRunnable = null;
        }
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof WhouseRegSecFragment) {
            mActivity.setTitle(getString(R.string.warehouse_reg_title));
        }
    }

    @Override
    public void requestDatas() {

    }

    @Override
    public void getChildView(int layoutId, View view) {

    }

    private void hideInput(View view) {
        InputMethodManager imm = (InputMethodManager)
                mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
